/*
Web: http://www.jsForms.com
Copyright (C) 2008  Igor Demyanov (mailto:Igor.Demyanov@gmail.com)
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
jsForms.Components.PropertyEventConfig = {
	/*Init: function(){
	 return jsForms.Components.Component.Init.call(this);
	 },*/
	SetObject: function(node){
		this.UpdateEventList(node);
		this.UpdatePropertiesList(node);
	},
	SetEditComponentType: function(compType){
		this.P.EditComponentType = compType;
	},
	UpdateVisual:function()
	{
		this._ExecEvent('onChange');
	},
	UpdateEventList: function(node){
		var eventListC = this.C.eventsList.empty();
		if (!node || node.isComponent != true || node.isRoot == true) {
			return;
		}
		
		var list = jsForms.DesignMode.GetEvents(node.Type, node);
		var comp = jsForms.Components[this.P.EditComponentType];
		for (var i in list) {
			var eD = jsForms.DesignMode.GetEvent(node, list[i]);
			jsForms.CreateComponent("EventItem").hide().appendTo(eventListC).Init()
				.SetValueList(comp)
				.SetEventObject(eD).show();
		};
			},
	UpdatePropertiesList: function(node){
		var propListC = this.C.propertiesList;
		propListC.empty();
		if (!node) {
			return;
		}
		//Create 'Name','Type','Text' - DOM Setting
		// NAME
		if (node.isRoot != true && node.isContent != true) {
			if (node.isText != true) {
				//Name
				var domName = jsForms.CreateComponent('DOMSettingItem');
				domName.SetName('Name');
				var dS = jsForms.DesignMode.GetDOMSetting(node, 'Name');
				domName._SetEvent('onApply',this,this.UpdateVisual);
				domName.hide().appendTo(propListC).Init().SetDOMSettingObject(dS).SetNode(node).show();
				if (node.isComponent == true) {
					//Type
					var domName = jsForms.CreateComponent('DOMSettingItem');
					domName.SetName('Type');
					var dS = jsForms.DesignMode.GetDOMSetting(node, 'Type');
					domName.hide().appendTo(propListC).Init().SetDOMSettingObject(dS).SetNode(node).show();
				}
			}
			if (node.isText == true) {
				// Text
				var domName = jsForms.CreateComponent('DOMSettingItem');
				domName.SetName('Text');
				var dS = jsForms.DesignMode.GetDOMSetting(node, 'Text');
				domName.hide().appendTo(propListC).Init().SetDOMSettingObject(dS).SetNode(node).show();
			}
			
			if (node.isComponent != true && node.isContent != true && node.isText != true) {
				//Tag
				var domM = jsForms.CreateComponent('DOMSettingItem');
				domM._SetEvent('onApply', this, this.Apply_PropertiesClick);
				domM.SetName('Tag');
				var dS = jsForms.DesignMode.GetDOMSetting(node, 'Tag');
				domM.hide().appendTo(propListC).Init().SetDOMSettingObject(dS).SetNode(node).show();
			}
		}
		if (node.isContent == true) {// INTO
			var domM = jsForms.CreateComponent('DOMSettingItem');
			domM._SetEvent('onApply', this, this.Apply_PropertiesClick);
			domM.SetName('In To');
			var dS = jsForms.DesignMode.GetDOMSetting(node, 'In To');
			domM.hide().appendTo(propListC).Init().SetDOMSettingObject(dS).SetNode(node).show();
		}
		
		//Create Component properties
		if (node.isComponent != true) {
			return;
		}
		
		var list = jsForms.DesignMode.GetProperties(node.Type, node);
		for (var i in list) {
			var pD = jsForms.DesignMode.GetProperty(node, list[i]);
			jsForms.CreateComponent("PropertyItem").hide().appendTo(propListC).Init().SetPropertyObject(pD).show();
		}
	}
};

jsForms.CreateCompileInfoByObject(
{
	Name: 'PropertyEventConfig',
	Properties: {
	},
	Events: {
		onChange: {}
	}
});
